import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    // 后台
    path: '/',
    redirect: '/i',
    component: () => import('@/views/header/index'),
    children: [
      {
        path: 'i',
        name: 'i',
        redirect: '/i/index',
        component: () => import('@/views/menu/index'),
        children: [
          {
            path: 'index',
            name: 'index',
            component: () => import('@/views/index.page'),
            meta: {
              title: '首页'
            }
          },
          {
            path: 'user',
            name: 'user',
            component: () => import('@/views/user/index'),
            meta: {
              title: '用户管理'
            }
          },
          {
            path: 'customer',
            name: 'customer',
            component: () => import('@/views/customer/manage.page'),
            meta: {
              title: '客户列表'
            }
          },
          {
            path: 'serve-item',
            name: 'serve-item',
            component: () => import('@/views/customer/serve-item.page'),
            meta: {
              title: '服务项目'
            }
          },
          {
            path: 'business',
            name: 'business',
            component: () => import('@/views/business/manage.page'),
            meta: {
              title: '商家列表'
            }
          },
          {
            path: 'business-type',
            name: 'business-type',
            component: () => import('@/views/business/type.page'),
            meta: {
              title: '商家类型'
            }
          },
          {
            path: 'revenues',
            name: 'revenues',
            component: () => import('@/views/statitics/revenues.page'),
            meta: {
              title: '营收查看'
            }
          },
          {
            path: 'grade-line',
            name: 'grade-line',
            component: () => import('@/views/statitics/grade-line.page'),
            meta: {
              title: '业绩走势'
            }
          },
          {
            path: 'grade-bar',
            name: 'grade-bar',
            component: () => import('@/views/statitics/grade-bar.page'),
            meta: {
              title: '服务项目统计'
            }
          },
          {
            path: 'order-count',
            name: 'order-count',
            component: () => import('@/views/statitics/order-count.page'),
            meta: {
              title: '单量统计'
            }
          },
          {
            path: 'economy-table',
            name: 'economy-table',
            component: () => import('@/views/economy/index'),
            meta: {
              title: '财务报表'
            }
          },
          {
            path: 'authority-manage',
            name: 'authority-manage',
            component: () => import('@/views/authority/index'),
            meta: {
              title: '权限管理'
            }
          }
        ]
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// 重置路由
// export function resetRouter() {
//   const newRouter = createRouter()
//   router.matcher = newRouter.matcher // reset router
// }

export default router
